home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / e33el2.zip / emacs / 19.33 / lisp / xscheme.el < prev    next >
Lisp/Scheme  |  1996-01-20  |  32KB  |  879 lines

  1. ;;; xscheme.el --- run Scheme under Emacs
  2.  
  3. ;; Copyright (C) 1986, 1987, 1989, 1990 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6. ;; Keywords: languages, lisp
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  22. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. ;; Boston, MA 02111-1307, USA.
  24.  
  25. ;;; Commentary:
  26.  
  27. ;; A major mode for editing Scheme and interacting with MIT's C-Scheme.
  28. ;;
  29. ;; Requires C-Scheme release 5 or later
  30. ;; Changes to Control-G handler require runtime version 13.85 or later
  31.  
  32. ;;; Code:
  33.  
  34. (require 'scheme)
  35.  
  36. (defvar scheme-program-name "scheme"
  37.   "*Program invoked by the `run-scheme' command.")
  38.  
  39. (defvar scheme-band-name nil
  40.   "*Band loaded by the `run-scheme' command.")
  41.  
  42. (defvar scheme-program-arguments nil
  43.   "*Arguments passed to the Scheme program by the `run-scheme' command.")
  44.  
  45. (defvar xscheme-allow-pipelined-evaluation t
  46.   "If non-nil, an expression may be transmitted while another is evaluating.
  47. Otherwise, attempting to evaluate an expression before the previous expression
  48. has finished evaluating will signal an error.")
  49.  
  50. (defvar xscheme-startup-message
  51.   "This is the Scheme process buffer.
  52. Type \\[advertised-xscheme-send-previous-expression] to evaluate the expression before point.
  53. Type \\[xscheme-send-control-g-interrupt] to abort evaluation.
  54. Type \\[describe-mode] for more information.
  55.  
  56. "
  57.   "String to insert into Scheme process buffer first time it is started.
  58. Is processed with `substitute-command-keys' first.")
  59.  
  60. (defvar xscheme-signal-death-message nil
  61.   "If non-nil, causes a message to be generated when the Scheme process dies.")
  62.  
  63. (defun xscheme-evaluation-commands (keymap)
  64.   (define-key keymap "\e\C-x" 'xscheme-send-definition)
  65.   (define-key keymap "\C-x\C-e" 'advertised-xscheme-send-previous-expression)
  66.   (define-key keymap "\eo" 'xscheme-send-buffer)
  67.   (define-key keymap "\ez" 'xscheme-send-definition)
  68.   (define-key keymap "\e\C-m" 'xscheme-send-previous-expression)
  69.   (define-key keymap "\e\C-z" 'xscheme-send-region))
  70.  
  71. (defun xscheme-interrupt-commands (keymap)
  72.   (define-key keymap "\C-c\C-s" 'xscheme-select-process-buffer)
  73.   (define-key keymap "\C-c\C-b" 'xscheme-send-breakpoint-interrupt)
  74.   (define-key keymap "\C-c\C-c" 'xscheme-send-control-g-interrupt)
  75.   (define-key keymap "\C-c\C-u" 'xscheme-send-control-u-interrupt)
  76.   (define-key keymap "\C-c\C-x" 'xscheme-send-control-x-interrupt))
  77.  
  78. (xscheme-evaluation-commands scheme-mode-map)
  79. (xscheme-interrupt-commands scheme-mode-map)
  80.  
  81. (defun run-scheme (command-line)
  82.   "Run MIT Scheme in an inferior process.
  83. Output goes to the buffer `*scheme*'.
  84. With argument, asks for a command line."
  85.   (interactive
  86.    (list (let ((default
  87.          (or xscheme-process-command-line
  88.              (xscheme-default-command-line))))
  89.        (if current-prefix-arg
  90.            (read-string "Run Scheme: " default)
  91.            default))))
  92.   (setq xscheme-process-command-line command-line)
  93.   (pop-to-buffer (xscheme-start-process command-line)))
  94.  
  95. (defun reset-scheme ()
  96.   "Reset the Scheme process."
  97.   (interactive)
  98.   (let ((process (get-process "scheme")))
  99.     (cond ((or (not process)
  100.            (not (eq (process-status process) 'run))
  101.            (yes-or-no-p
  102. "The Scheme process is running, are you SURE you want to reset it? "))
  103.        (message "Resetting Scheme process...")
  104.        (if process (kill-process process t))
  105.        (xscheme-start-process xscheme-process-command-line)
  106.        (message "Resetting Scheme process...done")))))
  107.  
  108. (defun xscheme-default-command-line ()
  109.   (concat scheme-program-name " -emacs"
  110.       (if scheme-program-arguments
  111.           (concat " " scheme-program-arguments)
  112.           "")
  113.       (if scheme-band-name
  114.           (concat " -band " scheme-band-name)
  115.           "")))
  116.  
  117. ;;;; Interaction Mode
  118.  
  119. (defun scheme-interaction-mode ()
  120.   "Major mode for interacting with the inferior Scheme process.
  121. Like  scheme-mode  except that:
  122.  
  123. \\[advertised-xscheme-send-previous-expression] sends the expression before point to the Scheme process as input
  124. \\[xscheme-yank-previous-send] yanks the expression most recently sent to Scheme
  125.  
  126. All output from the Scheme process is written in the Scheme process
  127. buffer, which is initially named \"*scheme*\".  The result of
  128. evaluating a Scheme expression is also printed in the process buffer,
  129. preceded by the string \";Value: \" to highlight it.  If the process
  130. buffer is not visible at that time, the value will also be displayed
  131. in the minibuffer.  If an error occurs, the process buffer will
  132. automatically pop up to show you the error message.
  133.  
  134. While the Scheme process is running, the modelines of all buffers in
  135. scheme-mode are modified to show the state of the process.  The
  136. possible states and their meanings are:
  137.  
  138. input        waiting for input
  139. run        evaluating
  140. gc        garbage collecting
  141.  
  142. The process buffer's modeline contains additional information where
  143. the buffer's name is normally displayed: the command interpreter level
  144. and type.
  145.  
  146. Scheme maintains a stack of command interpreters.  Every time an error
  147. or breakpoint occurs, the current command interpreter is pushed on the
  148. command interpreter stack, and a new command interpreter is started.
  149. One example of why this is done is so that an error that occurs while
  150. you are debugging another error will not destroy the state of the
  151. initial error, allowing you to return to it after the second error has
  152. been fixed.
  153.  
  154. The command interpreter level indicates how many interpreters are in
  155. the command interpreter stack.  It is initially set to one, and it is
  156. incremented every time that stack is pushed, and decremented every
  157. time it is popped.  The following commands are useful for manipulating
  158. the command interpreter stack:
  159.  
  160. \\[xscheme-send-breakpoint-interrupt]    pushes the stack once
  161. \\[xscheme-send-control-u-interrupt]    pops the stack once
  162. \\[xscheme-send-control-g-interrupt]    pops everything off
  163. \\[xscheme-send-control-x-interrupt]    aborts evaluation, doesn't affect stack
  164.  
  165. Some possible command interpreter types and their meanings are:
  166.  
  167. [Evaluator]    read-eval-print loop for evaluating expressions
  168. [Debugger]    single character commands for debugging errors
  169. [Where]        single character commands for examining environments
  170.  
  171. Starting with release 6.2 of Scheme, the latter two types of command
  172. interpreters will change the major mode of the Scheme process buffer
  173. to scheme-debugger-mode , in which the evaluation commands are
  174. disabled, and the keys which normally self insert instead send
  175. themselves to the Scheme process.  The command character ? will list
  176. the available commands.
  177.  
  178. For older releases of Scheme, the major mode will be be
  179. scheme-interaction-mode , and the command characters must be sent as
  180. if they were expressions.
  181.  
  182. Commands:
  183. Delete converts tabs to spaces as it moves back.
  184. Blank lines separate paragraphs.  Semicolons start comments.
  185. \\{scheme-interaction-mode-map}
  186.  
  187. Entry to this mode calls the value of scheme-interaction-mode-hook
  188. with no args, if that value is non-nil.
  189.  Likewise with the value of scheme-mode-hook.
  190.  scheme-interaction-mode-hook is called after scheme-mode-hook."
  191.   (interactive)
  192.   (kill-all-local-variables)
  193.   (scheme-interaction-mode-initialize)
  194.   (scheme-mode-variables)
  195.   (make-local-variable 'xscheme-previous-send)
  196.   (run-hooks 'scheme-mode-hook 'scheme-interaction-mode-hook))
  197.  
  198. (defun scheme-interaction-mode-initialize ()
  199.   (use-local-map scheme-interaction-mode-map)
  200.   (setq major-mode 'scheme-interaction-mode)
  201.   (setq mode-name "Scheme Interaction"))
  202.  
  203. (defun scheme